package com.woniu.mashangxiadan.miniapp.controller;

import com.woniu.mashangxiadan.common.Result;
import com.woniu.mashangxiadan.form.UserForm;
import com.woniu.mashangxiadan.model.Dish;
import com.woniu.mashangxiadan.model.OrderInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Map;

@RestController
@Api(tags = "用户小程序的Api", description = "提供用户小程序相关的 Rest API")
@RequestMapping("/user")
public class MiniAppController {

    @GetMapping("/getScanInfo")
    @ApiOperation("用户扫码传入用户信息和桌位ID, 返回菜品列表或要求支付之前未结账的订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userform", value = "前端穿回来的user对象", dataType = "UserForm"),
            @ApiImplicitParam(name="deskId",value = "桌位id", dataType = "int")
    })
    public Result getScanInfo(@RequestBody UserForm userform, Integer deskId) {
        return Result.success(new ArrayList<Dish>());
    }

    @GetMapping("/getUncheckedOrders")
    @ApiOperation("若用户上次未支付，请求此方法得到该用户所有未支付的订单，要求支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", dataType = "int")
    })
    public Result getUncheckedOrders(Integer userId) {
        return Result.success(new OrderInfo());
    }

    @GetMapping("/getFoodList")
    @ApiOperation("拉取餐厅菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "restaurantId", value = "商家Id", dataType = "int")
    })
    public Result getFoodList(Integer restaurantId) {
        return Result.success(new ArrayList<Dish>());
    }

    @PostMapping("/orderFoodList")
    @ApiOperation("用户提交点餐列表,map(菜品id，菜品数量)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "foods", value = "菜品id，菜品数量", dataType = "Map")
            ,@ApiImplicitParam(name = "userId", value = "用户Id", dataType = "int")
            ,@ApiImplicitParam(name="deskId",value = "桌位id", dataType = "int")
    })
    public Result orderFoodList(Map<Integer, Integer> foods, Integer userId, Integer deskId) {
        return Result.success();
    }

    @PostMapping("/confirmOrder")
    @ApiOperation("用户确认已经点好餐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", dataType = "int")
            ,@ApiImplicitParam(name="orderId",value = "订单id", dataType = "int")
    })
    public Result confirmOrder(Integer userId, Integer orderId) {
        return Result.success();
    }

    @GetMapping("/getOrderedFood")
    @ApiOperation("用户拉取当前订单的已点菜品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单Id", dataType = "int")
    })
    public Result getOrderedFood(Integer orderId) {
        return Result.success();
    }

    @DeleteMapping("/cancelDish")
    @ApiOperation("确认订单之前用户可以从已点的列表里面取消餐品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单Id", dataType = "int")
            ,@ApiImplicitParam(name = "dishId", value = "菜品Id", dataType = "int")
    })
    public Result cancelDish(Integer orderId, Integer dishId) {
        return Result.success();
    }

    @PostMapping("/checkOrder")
    @ApiOperation("用户支付订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name="orderIds",value = "支付本次所有的订单id", dataType = "Integer[]")
            ,@ApiImplicitParam(name = "userId", value = "用户Id", dataType = "int")

    })
    public Result checkOrder(Integer[] orderIds, Integer userId) {
        return null;
    }

}
